/* ***********************************************************************
 * 项目名称:油耗
 * 项目组:
 * 创建时间:2017.7.11
 * 创建人:马方印
 * 用途:
 * 版本:1.0
 * 修改记录:    修改内容   修改原因   修改人   修改时间
 *               无        无       无       无
 *************************************************************************/
#import "YZRecordHeaderFooterView.h"
#import "YZInputOrOutputGasolineModel.h"

@implementation YZRecordHeaderFooterView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self addSubview:self.nameLabel];
        [self addSubview:self.litreLabel];
        [self addSubview:self.timeLable];
        [self addSubview:self.separatorView];
        [self addSubview:self.topSeparatorView];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showDetailTap:)];
        [self.contentView addGestureRecognizer:tap];
        
        [self setSubViewsFrame];
    }
    
    return  self;
}

#pragma mark - 点击当前组头
- (void)showDetailTap:(UITapGestureRecognizer *)sender{
    
    if (_showDetailCompletionHandle) {
        
        _showDetailCompletionHandle(self.listErrorModel);
    }
}

#pragma mark - 数据源赋值
- (void)setListErrorModel:(YZListErrorModel *)listErrorModel{
    _listErrorModel = listErrorModel;
    
    //名称
    if (self.type == 0) {
        
        self.nameLabel.text = listErrorModel.unit;
        //油量
        self.litreLabel.text = [NSString stringWithFormat:@"%.1fL",[listErrorModel.iol floatValue]];
        //时间
        NSString *time = [LZXHelper getTimeStrWithOldDateFomatter:@"YYYY-MM-dd HH:mm:ss" DateStr:listErrorModel.time newFormatter:@"YYYY-MM-dd"];
        self.timeLable.text = time;
    }
    else if (self.type == 1){
        
        self.nameLabel.text = listErrorModel.errorUnit;
        //油量
        self.litreLabel.text = [NSString stringWithFormat:@"%.1fL",[listErrorModel.iol floatValue]];
        //时间
        NSString *time = [LZXHelper getTimeStrWithOldDateFomatter:@"YYYY-MM-dd HH:mm:ss" DateStr:listErrorModel.time newFormatter:@"YYYY-MM-dd"];
        self.timeLable.text = time;
    }
    else if (self.type == 2){
        
        self.nameLabel.text = listErrorModel.outcar;
        //油量
        self.litreLabel.text = [NSString stringWithFormat:@"%.1fL",[listErrorModel.iol floatValue]];
        //时间
        NSString *time = [LZXHelper getTimeStrWithOldDateFomatter:@"YYYY-MM-dd'T'HH:mm:ss" DateStr:listErrorModel.time newFormatter:@"YYYY-MM-dd"];
        self.timeLable.text = time;
    }
}

#pragma mark - 布局
- (void)setSubViewsFrame{
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.mas_left);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.right.mas_equalTo(self.litreLabel.mas_left);
        make.width.mas_equalTo(self.litreLabel);
    }];
    
    [self.litreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.nameLabel.mas_right);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.right.mas_equalTo(self.timeLable.mas_left);
        make.width.mas_equalTo(self.timeLable);
    }];
    
    [self.timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.litreLabel.mas_right);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.right.mas_equalTo(self.mas_right);
    }];
    
    [self.separatorView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.mas_bottom);
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.height.mas_equalTo(@0.5);
    }];
    
    [self.topSeparatorView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.mas_top);
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.height.mas_equalTo(@0.5);
    }];
}

#pragma mark - 懒加载
- (UILabel *)timeLable{
    
    if (!_timeLable) {
        
        _timeLable = [[UILabel alloc]init];
        _timeLable.text = @"2017-07-07";
        _timeLable.font = [UIFont systemFontOfSize:18.0f];
        _timeLable.textColor = COLOR(0, 153, 204, 1);
        _timeLable.frame = CGRectMake(0, 64, kScreenWidth, 44);
        _timeLable.textAlignment = NSTextAlignmentCenter;
    }
    
    return _timeLable;
}

- (UILabel *)litreLabel{
    
    if (!_litreLabel) {
        
        _litreLabel = [[UILabel alloc]init];
        _litreLabel.text = @"28.8L";
        _litreLabel.font = [UIFont systemFontOfSize:18.0f];
        _litreLabel.textColor = COLOR(0, 153, 204, 1);
        _litreLabel.frame = CGRectMake(0, 64, kScreenWidth, 44);
        _litreLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _litreLabel;
}

- (UILabel *)nameLabel{
    
    if (!_nameLabel) {
        
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"川D63525";
        _nameLabel.font = [UIFont systemFontOfSize:18.0f];
        _nameLabel.textColor = COLOR(0, 153, 204, 1);
        _nameLabel.frame = CGRectMake(0, 64, kScreenWidth, 44);
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _nameLabel;
}

- (UIView *)separatorView{
    
    if (!_separatorView) {
        
        _separatorView = [[UIView alloc]init];
        _separatorView.backgroundColor = [UIColor colorWithHexString:@"CCCCCC"];
    }
    
    return _separatorView;
}

- (UIView *)topSeparatorView{
    
    if (!_topSeparatorView) {
        
        _topSeparatorView = [[UIView alloc]init];
        _topSeparatorView.backgroundColor = [UIColor colorWithHexString:@"CCCCCC"];
    }
    
    return _topSeparatorView;
}

@end
